package com.shooter.utils;

import com.shooter.dao.DbConfig;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;

/**
 * Created by BLACK on 2017/6/19.
 */
public class PrintUtil {
    public static void printMsg(String msg) {
        System.out.println(msg);
    }

    public static void printError(String msg) {
        printError(new Exception(msg));
    }

    public static void printError(Exception e) {
        String path = DbConfig.class.getResource("/").getPath() + "/log/";
        String fileName = "ErrorLog-" + System.currentTimeMillis() + ".txt";
        File file = new File(path);
        file.mkdirs();
        file = new File(path + fileName);
        PrintStream stream = null;
        try {
            stream = new PrintStream(file);
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        }
        e.printStackTrace(stream);
        stream.flush();
        stream.close();
        e.printStackTrace();
    }
}
